
; OLPC XO-1.75 startup code, based on example code provided
; with the Keil development tools.

		NAME	EC_STARTUP


program		segment   code
?stack		segment   idata

		rseg	?stack
		ds	1

                extrn code (main)
                extrn code (early_startup)

		; "?c_startup" symbol is magic
		public	?c_startup

                cseg     at    0000h

?c_startup:     ljmp     startup1

                rseg     program
    startup1:
		mov     sp,#?stack-1

		; call into C for h/w init
		lcall	early_startup

		mov	a,r7	 ; return value chooses data init or not
		jz	clear_data
		ljmp	main

    clear_data:
		; clear 256 bytes of idata
		mov	r0,#0xff
		clr	a
	iloop:	mov	@r0,a
		djnz	r0,iloop


		; clear xdata -- bounds passed in from makefile
		mov	dptr,#XDATASTART
		mov	r7,#low(XDATALEN)
		mov	r6,#high(XDATALEN)
		clr	a
	xloop:	movx	@dptr,a
		inc	dptr
		djnz	r7,xloop
		djnz	r6,xloop

		mov     sp,#?stack-1
	        ljmp	main

                end
